package com.demo.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.common.ResultData;
import com.demo.entity.TestEntity;
import com.demo.mapper.TestMapper;
import com.demo.service.TestService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangfengchen
 * @since 2024-05-17
 */
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements TestService {


  @Override
  public ResultData add() {
    TestEntity testEntity = new TestEntity();
    testEntity.setId(IdUtil.getSnowflakeNextId());
    testEntity.setUsername(IdUtil.getSnowflakeNextIdStr());
    testEntity.setAge(18);
    testEntity.setCreateTime(new Date());
//    DataSourceContextHolder.setDataSourceKey(DynamicDSEnum.MASTER.getDesc());
    super.save(testEntity);
//    DataSourceContextHolder.setDataSourceKey(DynamicDSEnum.SLAVE.getDesc());
//    super.save(testEntity);
//    DataSourceContextHolder.clearDataSourceKey();
//    int i = 1 / 0;
//    DataSourceContextHolder.clearDataSourceKey();
    return ResultData.success();
  }


}
